package com.stylefeng.guns.biz.nav.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.nav.model.TNavList;
import com.stylefeng.guns.biz.nav.service.ITNavListService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 底部导航控制器
 *
 * @author fengshuonan
 * @Date 2018-06-14 06:34:11
 */
@Controller
@RequestMapping("/tNavList")
public class TNavListController extends BaseController {

    private String PREFIX = "/app/tNavList/";

    @Autowired
    private ITNavListService tNavListService;

    /**
     * 跳转到底部导航首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tNavList.html";
    }

    /**
     * 跳转到添加底部导航
     */
    @RequestMapping("/tNavList_add")
    public String tNavListAdd() {
        return PREFIX + "tNavList_add.html";
    }

    /**
     * 跳转到修改底部导航
     */
    @RequestMapping("/tNavList_update/{tNavListId}")
    public String tNavListUpdate(@PathVariable Long tNavListId, Model model) {
        TNavList tNavList = tNavListService.selectById(tNavListId);
        model.addAttribute("item",tNavList);
        LogObjectHolder.me().set(tNavList);
        return PREFIX + "tNavList_edit.html";
    }

    /**
     * 获取底部导航列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	EntityWrapper<TNavList> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id_key", appid);
        return tNavListService.selectList(wrapper);
    }

    /**
     * 新增底部导航
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TNavList tNavList) {
        tNavListService.insert(tNavList);
        return SUCCESS_TIP;
    }

    /**
     * 删除底部导航
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long tNavListId) {
        tNavListService.deleteById(tNavListId);
        return SUCCESS_TIP;
    }

    /**
     * 修改底部导航
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TNavList tNavList) {
        tNavListService.updateById(tNavList);
        return SUCCESS_TIP;
    }

    /**
     * 底部导航详情
     */
    @RequestMapping(value = "/detail/{tNavListId}")
    @ResponseBody
    public Object detail(@PathVariable("tNavListId") Long tNavListId) {
        return tNavListService.selectById(tNavListId);
    }
}
